#include "./../Include/public.h"
void choose_course()
{
	printf("输入要选课的学生的学号: \n");
	char sno[12];
	scanf("%s", sno);
	struct stu *p = head_stu;
	while (p != NULL) {
		if (!strcmp(p->sno, sno)) break;
		p = p->next;
	}
	if (p == NULL) {
		printf("该学生不存在！\n");
		return;
	}
	printf("输入要选择课程的课程号: \n");
	int cno;
	scanf("%d",&cno);
	
	for (int i=0;i<p->courses[0];i++) {
		if (cno == p->courses[i+1]) {
			printf("该课程已选\n");
			return;
		}
	} 
	
	struct course *q = head_course;
	int flag = 0;
	while (q != NULL) {
		if (q->cno == cno && q->chose < q->limit) {
			q->chose++; 
			flag = 1;
			break;
		} else if(q->cno == cno && q->chose >= q->limit) {
			flag = 2;
			break;
		}
		q = q->next;
	}
	if (flag == 1) {
		p->courses[++p->courses[0]] = cno;
		p->sum += q->score;
		printf("OK\n");
	} else if(flag == 0) {
		printf("课程不存在！\n");
	}else if(flag == 2) {
		printf("课程已满！\n");
	}
	
} 
